<template>
    <div class="setup_body">
        <div class="setup_">
            <div class="topbar">
                <div class="backUser"><a href="#/user" style="text-decoration: none;">&lt;</a></div>
                <div class="setup_text">
                    <span>系统设置</span>
                </div>
            </div>
            <ul>
                <li>
                    <el-button class="my-button" @click="goToMy">个人资料</el-button>
                </li>
                <li>
                    <el-button class="my-button" @click="goToUpdatePwd">修改密码</el-button>
                </li>
                <li>
                    <el-button class="my-button" @click="goToLogin">退出登录</el-button>
                </li>
            </ul>
        </div>
    </div>
</template>
    
<script>
import { jwtDecode } from 'jwt-decode';

export default {
    data() {
        return {
            studentData: [],//学生数据
        };
    },
    computed: {

    },
    methods: {
        // 跳转到个人信息页面
        goToMy() {
            const jwt = localStorage.getItem('jwt');
            if (jwt) {
                this.$router.push('/my');
            }
            else {
                this.$message.error("未登录，无法进行查看个人资料");
            }

        },
        goToUpdatePwd() {
            const jwt = localStorage.getItem('jwt');
            if (jwt) {
                this.$router.push('/updatePwd');
            }
            else {
                this.$message.error("未登录，无法进行修改密码");
            }

        },

        // 跳转到登录页面
        goToLogin() {
            this.clearUserSession();
            this.$router.push('/login');
        },
        clearUserSession() {
            // 执行清除用户登录状态的操作，例如：
            // 清除本地存储中的 token
            localStorage.removeItem('jwt');
            // 其他清除操作...
        },


    },
    mounted() {
        const jwt = localStorage.getItem('jwt');
        if (jwt) {
            const decoded = jwtDecode(jwt);
            const userId = decoded.id; // 确保你的token结构中有id字段
            this.$http.get("/api/students/queryOneStudentById/" + userId).then(response => {  /*刷新页面*/
                this.studentData = response.data.data;
            }).catch(() => {
                this.$message.error("请求错误");
            });
            this.$http.get("/api/orders/queryOneStudentOrder/" + userId).then(response => {  /*刷新页面*/
                this.orderData = response.data.data.rows;
            }).catch(() => {
                this.$message.error("请求错误");
            });


        }
    },
};
</script>
    
<style>
@import "@/style/setup.css";
</style>